package com.heima.Text;

import com.heima.minio.Application;
import com.jlefebure.spring.boot.minio.MinioService;
import org.apache.http.entity.ContentType;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;


import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class)
public class text {
    @Autowired
    private MinioService minioService;

    /**
     * 文件上传
     * @throws Exception
     */
    @Test
    public void test01() throws Exception {
    Path path = Paths.get("a.jpg");
        FileInputStream stream = new FileInputStream("D:\\WeGameApps\\Desktop\\111\\20230129150835_59024.jpg");
        minioService.upload(path,stream,ContentType.IMAGE_JPEG);
    }

    /**
     * 文件下载
     * @throws Exception
     */
    @Test
    public void test02() throws Exception {
        InputStream inputStream = minioService.get(Paths.get("a.jpg"));
        Files.copy(inputStream,Paths.get("d:\\b.jpg"));
    }

    /**
     * 文件删除
     * @throws Exception
     */
    @Test
    public void test03() throws Exception {
     minioService.remove(Paths.get("a.jpg"));
    }

}
